POV-Ray : Newsgroups : povray.beta-test : Bug List : Re: Bug List Server Time
28 Jul 2024 18:24:12 EDT (-0400)
  Re: Bug List  
From: Warp
Date: 5 Feb 2008 10:14:48
Message: <47a87d61@news.povray.org>
Tim Attwood <tim### [at] comcastnet> wrote:
> Malformed Nested #declare Doesn't Raise Error
> ---------------------------------------------
> A declare of the form...
> #declare Weird = #declare Aval = 1;
> parses without an error. This is probably should raise an error,
> or at least a warning, since it can terminate inside nested
> #if and #while statements. Existed in 3.6 as well.

  This is not a bug nor an error, just a side-effect of how the parser works.

  When the parser finds "#declare Weird = " it will then recursively parse
for "anything that evaluates to something which can be declared". This
"anything" is parsed like any other SDL. This includes, among other things,
the possibility if putting #-commands in there.

  Thus the next thing it finds is "#declare", which is just fine, and
will parse that (creating the identifier 'Aval' and assigning "1" to it).
When this is done, parsing will continue as normal, and whatever comes
after that in-between #declare will be assigned to 'Weird'.

  It's exactly this kind of parsing which allows doing things like:

#declare Weird = some_macro(1, 2, 3);

where the macro may have anything inside it (including #declares and such).

  Your example line does, in fact, give an error, because there's nothing
to assign to 'Weird' because nothing comes after the second #declare.
This, however, would be perfectly ok:

#declare Weird = #declare Aval = 1; 2;

  It may look a bit weird, but it's well defined: While parsing the parameter
to #declare, a second #declare is found, which is parsed recursively. After
it has been parsed, parsing continues normally, so it finds the '2' and
assigns it to 'Weird'.

  I'm not sure if changing this behavior is desirable. It would make a lot
of other things a lot harder to parse.

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.